$(function() {
	for (var i = 150; i < 200; i++) {
		var s = "";
		if ($("#height").attr('defaultData') == i) {
			s = "<option class='selectList' value='" + i + "' selected='true'>" + i + "厘米</option>";
		} else {
			s = "<option class='selectList' value='" + i + "'>" + i + "厘米</option>";
		}
		$("#height").append(s);
	}
	judgeDefaultData($("#height"), 0);

	for (var i = 70; i < 200; i += 10) {
		var s = "";
		if ($("#weight").attr('defaultData') == i) {
			s = "<option class='selectList' value='" + i + "' selected='true'>" + i + "斤</option>";
		} else {
			s = "<option class='selectList' value='" + i + "'>" + i + "斤</option>";
		}
		$("#weight").append(s);
	}
	judgeDefaultData($("#weight"), 0);

	for (var i = 0; i < 8; i++) {
		judgeDefaultData($("#sel_blood"), i);
		judgeDefaultData($("#sel_work"), i);
		judgeDefaultData($("#sel_edu"), i);
		judgeDefaultData($("#sel_marriage"), i);
		judgeDefaultData($("#sel_salary"), i);
		judgeDefaultData($("#sel_house"), i);
	}

	function judgeDefaultData(defaultData, i) {//默认选择
		if (defaultData.attr('defaultData') == 0) {
			defaultData.css("color", "red");
		} else {
			defaultData.css("color", "#666666");
		}
		if (defaultData.attr('defaultData') == i) {
			defaultData.children().eq(i).attr('selected', 'true');
		}
	}

	var birthdays = $("#sel_year").attr('defaultData').split("-");

	for (var i = 1954; i < 1996; i++) {
		var s = "";
		if (birthdays[0] == i) {
			s = "<option class='selectList' value='" + i + "' selected='true'>" + i + "年</option>";
		} else {
			s = "<option class='selectList' value='" + i + "'>" + i + "年</option>";
		}
		$("#sel_year").append(s);
	}
	for (var i = 1; i < 13; i++) {
		var s = "";
		if (birthdays[1] == i) {
			s = "<option class='selectList' value='" + i + "' selected='true'>" + i + "月</option>";
		} else {
			s = "<option class='selectList' value='" + i + "'>" + i + "月</option>";
		}
		$("#sel_month").append(s);
	}

	$("#sel_month").change(function() {
		setDay(1);
	});

	function setDay(defaultDay) {
		var year = $("#sel_year").val();
		var month = $("#sel_month").val();
		var days = GetMDay(year, month);
		$("#sel_day").empty();
		for (var i = 1; i < days + 1; i++) {
			var s = "";
			if (defaultDay == i) {
				s = "<option class='selectList' value='" + i + "' selected='true'>" + i + "号</option>";
			} else {
				s = "<option class='selectList' value='" + i + "'>" + i + "号</option>";
			}
			$("#sel_day").append(s);
		}
	}

	setDay(birthdays[2]);

	$('#saveBaseInfoBtn').click(function() {
		if (!testQQ()) {
			art.dialog.alert('QQ输入格式有误').time(2);
		} else {
			$.post("userAjax_updateBaseData", {
				"user.name" : $("#nickName").val(),
				"baseData.qq" : $("#qq").val(),
				"baseData.height" : $("#height").val(),
				"baseData.blood" : $("#sel_blood").val(),
				"baseData.weight" : $("#weight").val(),
				"baseData.profession" : $("#sel_work").val(),
				"baseData.education" : $("#sel_edu").val(),
				"baseData.marryCondition" : $("#sel_marriage").val(),
				"baseData.monthlyIncome" : $("#sel_salary").val(),
				"baseData.birthplace" : $("#sel_ht_prov").val() + "-" + $("#sel_ht_city").val(),
				"baseData.apartment" : $("#sel_prov").val() + "-" + $("#sel_city").val() + "-" + $("#sel_area").val(),
				"baseData.house" : $("#sel_house").val(),
				"baseData.birthday" : $("#sel_year").val() + "-" + $("#sel_month").val() + "-" + $("#sel_day").val(),
			}, function(data) {
				if (data != "true") {
					art.dialog.alert('发生未知错误！！！').time(2);
				}else{
					art.dialog.alert('保存成功！！').time(2);
				}
			});
		}
		return false;
	});

	var apartments;
	if ($("#sel_ht_prov").attr('defaultData') != null && $("#sel_ht_prov").attr('defaultData') != "null" && $("#sel_ht_prov").attr('defaultData') != "") {
		apartments = $("#sel_prov").attr('defaultData').split("-");
	} else {
		apartments = ["省份", "地级市", "市、县级市"];
	}
	var s1 = ["sel_prov", "sel_city", "sel_area"];
	_init_area(s1, apartments);

	var birthplaces;
	if ($("#sel_ht_prov").attr('defaultData') != null && $("#sel_ht_prov").attr('defaultData') != "null" && $("#sel_ht_prov").attr('defaultData') != "") {
		birthplaces = $("#sel_ht_prov").attr('defaultData').split("-");
	} else {
		birthplaces = ["省份", "地级市"];
	}
	var s2 = ["sel_ht_prov", "sel_ht_city"];
	_init_area(s2, birthplaces);
});

function GetMDay(y, m) {
	var mday = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	if ((y % 40 == 0 && y % 100 != 0) || y % 400 == 0)//判断是否是闰月
		mday[1] = 29;
	return mday[m - 1];

}

function testQQ() {
	var a = $("#qq").val();
	if (a) {
		var b = /^[0-9]{5,13}$/gi;
		if (!b.test(a)) {
			return false;
		}
	}
	return true;
}